package com.jintoufs.service.activiti.impl;

import com.jintoufs.dao.QueryFilters;
import com.jintoufs.dao.activiti.ActivitiMapper;
import com.jintoufs.dao.activiti.ActivitiProductMapper;
import com.jintoufs.domain.activiti.Activiti;
import com.jintoufs.domain.activiti.ActivitiProduct;
import com.jintoufs.service.activiti.ActivitiService;
import com.jintoufs.util.valid.ValidUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by xufei on 2017/12/20.
 */
@Service
public class ActivitiServiceImpl implements ActivitiService{

    @Resource
    private ActivitiMapper activitiMapper;
    @Resource
    private ActivitiProductMapper activitiProductMapper;

    @Override
    public List<Map> queryByParams(Map<String, Object> params) {
        return activitiMapper.queryByParams(params);
    }


    @Override
    public List<Map<String,Object>> getByFilter(QueryFilters filters) {
        List<Map<String,Object>> result = activitiMapper.getByFilter(filters);
        return result;
    }

    @Override
    public Activiti getById(Integer id) {
        return activitiMapper.queryByPrimaryKey(id);
    }


    @Override
    public Activiti save(Activiti activiti) {
        try {
            if (ValidUtil.isEmpty(activiti.getId())) {
                activitiMapper.insert(activiti);
            }
            return activiti;
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public Integer update(Activiti activiti) {
        return activitiMapper.updateByPrimaryKeySelective(activiti);
    }

    @Override
    public void delete(Integer id) {
        activitiProductMapper.deleteByActivitiId(id);
        activitiMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insertActivitiProduct(ActivitiProduct activitiProduct) {
        activitiProductMapper.insert(activitiProduct);
    }

    @Override
    public List<Map<String, Object>> selectByParams(Map<String, Object> param) {
        return activitiMapper.selectByParams(param);
    }
}
